package com.Endurancer.manager.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.Endurancer.manager.domain.dto.VisitorDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.Endurancer.common.annotation.Log;
import com.Endurancer.common.core.controller.BaseController;
import com.Endurancer.common.core.domain.AjaxResult;
import com.Endurancer.common.enums.BusinessType;
import com.Endurancer.manager.domain.SiteInformation;
import com.Endurancer.manager.service.ISiteInformationService;
import com.Endurancer.common.utils.poi.ExcelUtil;
import com.Endurancer.common.core.page.TableDataInfo;

/**
 * 博客站点资讯统计Controller
 *
 * @author ruoyi
 * @date 2025-02-11
 */
@RestController
@RequestMapping("/manager/information")
public class SiteInformationController extends BaseController
{
    @Autowired
    private ISiteInformationService siteInformationService;
    /**
     * 修改博客站点资讯统计
     */
    @PutMapping("/editInformation")
    public AjaxResult editInformation(@RequestBody SiteInformation siteInformation)
    {
        return toAjax(siteInformationService.editInformation(siteInformation));
    }

    /**
     * 修改博客访问量和访问人数
     */
    @PutMapping( "/editVisitor")
    public AjaxResult editVisitor(@RequestBody VisitorDto visitorDto)
    {
        return toAjax(siteInformationService.editVisitor(visitorDto));
    }
    /**
     * 查询博客站点资讯统计列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SiteInformation siteInformation)
    {
        startPage();
        List<SiteInformation> list = siteInformationService.selectSiteInformationList(siteInformation);
        return getDataTable(list);
    }

    /**
     * 导出博客站点资讯统计列表
     */
    @PreAuthorize("@ss.hasPermi('manager:information:export')")
    @Log(title = "博客站点资讯统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SiteInformation siteInformation)
    {
        List<SiteInformation> list = siteInformationService.selectSiteInformationList(siteInformation);
        ExcelUtil<SiteInformation> util = new ExcelUtil<SiteInformation>(SiteInformation.class);
        util.exportExcel(response, list, "博客站点资讯统计数据");
    }

    /**
     * 获取博客站点资讯统计详细信息
     */
    @PreAuthorize("@ss.hasPermi('manager:information:query')")
    @GetMapping(value = "/{infoId}")
    public AjaxResult getInfo(@PathVariable("infoId") Long infoId)
    {
        return success(siteInformationService.selectSiteInformationByInfoId(infoId));
    }

    /**
     * 新增博客站点资讯统计
     */
    @PreAuthorize("@ss.hasPermi('manager:information:add')")
    @Log(title = "博客站点资讯统计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SiteInformation siteInformation)
    {
        return toAjax(siteInformationService.insertSiteInformation(siteInformation));
    }

    /**
     * 修改博客站点资讯统计
     */
    @PreAuthorize("@ss.hasPermi('manager:information:edit')")
    @Log(title = "博客站点资讯统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SiteInformation siteInformation)
    {
        return toAjax(siteInformationService.updateSiteInformation(siteInformation));
    }

    /**
     * 删除博客站点资讯统计
     */
    @PreAuthorize("@ss.hasPermi('manager:information:remove')")
    @Log(title = "博客站点资讯统计", businessType = BusinessType.DELETE)
	@DeleteMapping("/{infoIds}")
    public AjaxResult remove(@PathVariable Long[] infoIds)
    {
        return toAjax(siteInformationService.deleteSiteInformationByInfoIds(infoIds));
    }
}
